package com.itheima.api.treeset.demo01;

/**
 * 使用TreeSet集合对象存储元素的时候，如果我们使用的是自然排序，
 * 那么就要求我们这个元素必须去实现Comparable这个接口
 */
public class Student implements Comparable<Student>{

    private String name;
    private int age;

    public Student() {
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public int compareTo(Student o) {
        int result = this.age - o.age;

        int result2 = result == 0 ? this.name.compareTo(o.name) : result;

        return result2;
    }
}
